<!--
 * @Description: 任务领取查看、审核详情
 * @Author: liyujie
 * @Date: 2021/10/27
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/10/27
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    审核答卷
                </div>
                <div
                    class="back"
                    @click="handleRoute('standardTaskReceiveList')"
                >
                    返回
                </div>
            </div>
            <!-- /header -->
            <div class="form-wrapper">
                <div class="status-view">
                    <template v-if="formData.verify_status === 0">
                        <div class="status-text warning">待审核</div>
                        <div class="status-desc-text">用户已提交任务反馈，请尽快审核~</div>
                    </template>
                    <template v-if="formData.verify_status === 1">
                        <div class="status-text success">审核通过</div>
                        <div class="status-desc-text">审核时间：{{ formData.verify_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}</div>
                    </template>
                    <template v-if="formData.verify_status === -1">
                        <div class="status-text danger">审核不通过</div>
                        <div class="status-desc-text">不通过原因：{{ formData.verify_fail_reason }}</div>
                    </template>
                    <div class="status-desc-text">提交审核时间：{{ formData.submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}</div>
                </div>
                <div class="form-view">
                    <div class="title-view">
                        <div class="task-title">
                            {{ formData.task_title }}
                        </div>
                        <div class="desc">
                            <div class="desc-item">上传学生昵称：{{ formData.true_name }}</div>
                            <div class="desc-item">上传学生学校：{{ formData.school_name }}</div>
                        </div>
                    </div>
                    <div class="form-content-view">
                        <div
                            class="question-item"
                            v-for="(item,index) in formData.submit_config"
                            :key="item.name"
                        >
                            <!--标题-->
                            <div class="question-item-title">
                                {{ index + 1 }}、{{ item.title }}
                            </div>
                            <!--标题描述-->
                            <div
                                class="question-item-title__intro"
                                v-if="item.intro"
                            >
                                {{ item.intro }}
                            </div>
                            <div class="question-item-content">
                                <!--单项填空-->
                                <template v-if="item.type === 1">
                                    <div class="input-view">
                                        {{ item.default.value }}
                                    </div>
                                </template>
                                <!--多项填空-->
                                <template v-if="item.type === 11">
                                    <div class="option-list">
                                        <div
                                            class="option-item"
                                            v-for="(option, i) in item.options"
                                            :key="i"
                                        >
                                            <div class="option-title">
                                                {{ option.title }}
                                            </div>
                                            <div class="input-view">
                                                {{ option.default_edit_content }}
                                            </div>
                                        </div>
                                    </div>
                                </template>
                                <!--单选/多选题-->
                                <template v-if="item.type === 2 || item.type === 3">
                                    <div class="select-option-list">
                                        <div
                                            class="select-option-item"
                                            v-for="(option, i) in item.options"
                                            :key="i"
                                        >
                                            <div class="option-title">
                                                <template v-if="item.type === 2">
                                                    <div class="title-icon">
                                                        <i
                                                            v-if="option.default_selected"
                                                            class="iconfont el-icon-hand-danxuan1"
                                                        />
                                                        <div
                                                            v-else
                                                            class="radio-default-icon"
                                                        />
                                                    </div>
                                                </template>
                                                <template v-if="item.type === 3">
                                                    <div
                                                        class="title-icon checkbox"
                                                        :class="{'selected': option.default_selected}"
                                                    >
                                                        <i
                                                            v-if="option.default_selected"
                                                            class="iconfont el-icon-hand-yixuanze"
                                                        />
                                                        <div
                                                            v-else
                                                            class="checkbox-default-icon"
                                                        />
                                                    </div>
                                                </template>
                                                <div class="title-value">{{ option.title }}</div>
                                            </div>
                                            <div class="option-intro">
                                                {{ option.intro }}
                                            </div>
                                            <div
                                                class="input-view"
                                                style="margin-top: 12px; margin-left: 28px"
                                                v-if="option.option_type === 2"
                                            >
                                                {{ option.default_edit_content ? option.default_edit_content : '' }}
                                            </div>
                                        </div>
                                    </div>
                                </template>
                                <!--图片上传-->
                                <template v-if="item.type === 5">
                                    <div
                                        class="upload-image-list"
                                        v-if="item.default.value.length"
                                    >
                                        <div
                                            class="upload-image-item"
                                            v-for="(option, i) in item.default.value"
                                            :key="i"
                                            @click="showPreview(item.default.value.map(image => image.value), i)"
                                        >
                                            <img
                                                :src="option.value"
                                                alt=""
                                            >
                                        </div>
                                    </div>
                                </template>
                                <!--单选/多选图片-->
                                <template v-if="item.type === 10 || item.type === 13">
                                    <div
                                        class="select-image-list"
                                        v-if="item.options.length"
                                    >
                                        <div
                                            v-for="(option, i) in item.options"
                                            :key="i"
                                            class="select-image-item"
                                            :class="{'selected': option.default_selected}"
                                        >
                                            <img
                                                :src="option.image_url"
                                                alt=""
                                                class="option-image"
                                                @click="showPreview(item.options.map(image => image.image_url), i)"
                                            >
                                            <div
                                                class="option-intro"
                                                v-if="option.intro"
                                                @click="showOptionIntro(option.intro)"
                                            >
                                                <i class="el-icon-more"/>
                                            </div>
                                            <div class="option-title">
                                                <template v-if="item.type === 13">
                                                    <div class="title-icon">
                                                        <i
                                                            v-if="option.default_selected"
                                                            class="iconfont el-icon-hand-danxuan1"
                                                        />
                                                        <div
                                                            v-else
                                                            class="radio-default-icon"
                                                        />
                                                    </div>
                                                </template>
                                                <template v-if="item.type === 10">
                                                    <div
                                                        class="title-icon checkbox"
                                                        :class="{'selected': option.default_selected}"
                                                    >
                                                        <i
                                                            v-if="option.default_selected"
                                                            class="iconfont el-icon-hand-yixuanze"
                                                        />
                                                        <div
                                                            v-else
                                                            class="checkbox-default-icon"
                                                        />
                                                    </div>
                                                </template>
                                                <div class="title-value">{{ option.title }}</div>
                                            </div>
                                        </div>
                                    </div>
                                </template>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="operating-view">
                <el-button
                    size="medium"
                    @click="handleRoute('standardTaskReceiveList')"
                >
                    返回
                </el-button>
                <el-button
                    size="medium"
                    class="reject"
                    v-if="formData.verify_status === 0"
                    @click="showVerifyDialog(-1)"
                >
                    不通过
                </el-button>
                <el-button
                    size="medium"
                    type="primary"
                    v-if="formData.verify_status === 0"
                    @click="showVerifyDialog(1)"
                >
                    通过
                </el-button>
            </div>
        </div>
        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import {back} from '@/mixin/back';
import {numberChinese} from "@/assets/js/utils";
import {videoPreviewDialog} from '@/components/common/video-preview';
import ImgPreview from "@/components/common/img-preview";

export default {
    name: 'StandardTaskReceiveDetail',
    mixins: [back],
    components: {ImgPreview},
    data() {
        return {
            apply_no: '',
            formData: {},
            authResult: {},
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
        };
    },
    computed: {},
    watch: {},
    filters: {},
    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '平台标准任务'}, {title: '任务领取', path: '/student/standard-task-receive-list'}, {title: '审核答卷'}]);
        this.authResult = this.$route.meta.authResult;
        this.apply_no = query.apply_no;
        this.getDetailData();
    },

    methods: {
        numberChinese,
        /**
         * @description 获取数据
         */
        getDetailData() {
            let params = {
                apply_no: this.apply_no
            };

            this.$post('/student/task_stuagent_student_task%5Cget_verify_detail', params, res => {
                if (res.code === 1) {
                    this.formData = res.data;
                    this.formData.submit_config = this.formData.submit_config.filter(item => item.type !== 12);
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * 预览图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         * @param index
         */
        showPreview(images, index) {
            if (images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images, index);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 显示审核操作弹窗
         * @param action -1拒绝 1 通过
         */
        async showVerifyDialog(action) {
            // 通过
            if (action === 1) {
                this.$zdConfirm('确认审核通过吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.handleVerify(this.apply_no, action);
                }).catch(() => {});
            } else {
                let reason = await this.$zdPrompt({
                    title: '审核不通过',
                    message: '审核不通过原因',
                    placeholder: '请输入未完成原因…'
                });

                if(reason) {
                    this.handleVerify(this.apply_no, action, reason);
                }
            }
        },

        /**
         * 审核
         * @param apply_no
         * @param verify_status
         * @param verify_fail_reason
         */
        handleVerify(apply_no, verify_status, verify_fail_reason) {
            let params = {
                apply_no,
                verify_status,
                verify_fail_reason,
            };

            this.$post('/student/task_stuagent_student_task%5Ccomplete_task_set_award', params, resp => {
                if (resp.code === 1) {
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                    this.getDetailData();
                    this.handleRoute('standardTaskReceiveList');
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 预览视频
         * @param url
         */
        previewVideo(url) {
            videoPreviewDialog({
                previewUrl: url
            });
        },

        /**
         * 现在选项介绍文案
         * @param intro
         */
        showOptionIntro(intro) {
            this.$zdPrompt({
                title: '图片选项说明',
                showText: intro
            });
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;
        overflow-x: hidden;
        /*header*/

        .header {
            height: 66px;
            padding-left: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;
            flex-shrink: 0;

            .header-title {
                font-size: 18px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                .project-title {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    margin-left: 12px;
                }
            }
            .option-button {
                display: flex;
                align-items: center;
                .button-item {
                    height: 48px;
                    padding: 0 24px;
                    border-right: 1px solid #F0F2F5;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #666666;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    cursor: pointer;
                    &.last {
                        border-right: 0;
                        color: #1890FF;
                    }
                    &:hover {
                        background: #F9F9F9;
                        transition: all 0.2s;
                    }
                }
            }
            .back {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                cursor: pointer;
                margin-right: 24px;
            }
        }
        .form-wrapper {
            overflow-y: auto;
            padding: 24px 56px;
            border-bottom: 1px solid #EBEEF5;
            flex: 1;
            &::-webkit-scrollbar {
                width: 6px;
            }
            .status-view {
                display: flex;
                flex-direction: column;
                border-bottom: 1px solid #F0F2F5;
                flex-shrink: 0;
                padding: 0 106px 24px;
                .status-text {
                    font-size: 16px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    &.warning {
                        color: #FFB726;
                    }
                    &.success {
                        color: #2FBDB3;
                    }
                    &.danger {
                        color: #F95B56;
                    }
                }
                .status-desc-text {
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #999999;
                    margin-top: 12px;
                }
            }
        }

        .form-view {
            margin-top: 32px;
            padding: 0 106px 24px;
            .title-view {
                .task-title {
                    font-size: 24px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #333333;
                    line-height: 24px;
                }
                .desc {
                    display: flex;
                    margin-top: 24px;
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #666666;
                    line-height: 24px;
                    &-item {
                        margin-right: 42px;
                    }
                }
            }
            .form-content-view {
                .question-item {
                    margin-top: 52px;
                    &-title {
                        font-size: 16px;
                        font-family: PingFangSC-Medium, PingFang SC;
                        font-weight: 500;
                        color: #333333;
                        line-height: 22px;
                        position: relative;
                        &:before {
                            content: "*";
                            font-size: 16px;
                            font-family: PingFangSC-Semibold, PingFang SC;
                            font-weight: 600;
                            color: #F53341;
                            line-height: 22px;
                            position: absolute;
                            left: -10px;
                            top: 0;
                        }
                    }
                    &-title__intro {
                        font-size: 12px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #999999;
                        line-height: 17px;
                        margin-top: 10px;
                    }
                    &-content {
                        margin-top: 16px;
                        .input-view {
                            min-height: 54px;
                            background: #F7F7F7;
                            border-radius: 4px;
                            border: 1px solid #D8DCE5;
                            font-size: 14px;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: #333333;
                            line-height: 24px;
                            padding: 15px 18px;
                            word-break: break-all;
                        }
                        // 多项填空
                        .option-list {
                            .option-item {
                                margin-bottom: 30px;
                                .option-title {
                                    font-size: 14px;
                                    font-family: PingFangSC-Regular, PingFang SC;
                                    font-weight: 400;
                                    color: #333333;
                                    line-height: 20px;
                                    margin-bottom: 12px;
                                }
                            }
                        }
                        // 单选多选
                        .select-option-list {
                            .select-option-item {
                                margin-bottom: 24px;
                                .option-title {
                                    display: flex;
                                    align-items: center;
                                    margin-bottom: 10px;
                                    .title-icon {
                                        margin-right: 10px;
                                        .radio-default-icon {
                                            width: 18px;
                                            height: 18px;
                                            border-radius: 50%;
                                            background: #F0F2F7;
                                            border: 1px solid #DCDFE6;
                                        }
                                        .checkbox-default-icon {
                                            width: 18px;
                                            height: 18px;
                                            background: #F0F2F7;
                                            border-radius: 3px;
                                            border: 1px solid #DCDFE6;
                                        }
                                        .iconfont {
                                            font-size: 18px;
                                            color: #20A0FF;
                                        }
                                        &.checkbox {
                                            width: 18px;
                                            height: 18px;
                                            display: flex;
                                            align-items: center;
                                            justify-content: center;
                                            border-radius: 3px;
                                            &.selected {
                                                background: #20A0FF;
                                            }
                                            .iconfont {
                                                color: #fff;
                                                font-size: 14px;
                                            }
                                        }
                                    }
                                    .title-value {
                                        font-size: 14px;
                                        font-family: PingFangSC-Regular, PingFang SC;
                                        font-weight: 400;
                                        color: #333333;
                                        line-height: 20px;
                                    }
                                }
                                .option-intro {
                                    font-size: 12px;
                                    font-family: PingFangSC-Regular, PingFang SC;
                                    font-weight: 400;
                                    color: #999999;
                                    line-height: 17px;
                                    padding-left: 28px;
                                }
                            }
                        }
                        // 上传图片
                        .upload-image-list {
                            display: flex;
                            flex-wrap: wrap;
                            .upload-image-item {
                                width: 132px;
                                height: 132px;
                                border-radius: 2px;
                                overflow: hidden;
                                margin-right: 15px;
                                margin-bottom: 20px;
                                cursor: pointer;
                                img {
                                    width: 100%;
                                    height: 100%;
                                }
                            }
                        }
                        // 单选多选图片
                        .select-image-list {
                            display: flex;
                            flex-wrap: wrap;
                            align-items: flex-start;
                            .select-image-item {
                                margin-right: 15px;
                                margin-bottom: 20px;
                                width: 132px;
                                min-height: 172px;
                                background: #FFFFFF;
                                border-radius: 4px;
                                overflow: hidden;
                                border: 1px solid #EEEEEE;
                                position: relative;
                                &.selected {
                                    border: 1px solid #20A0FF;
                                }
                                .option-image {
                                    width: 132px;
                                    height: 132px;
                                    cursor: pointer;
                                }
                                .option-intro {
                                    position: absolute;
                                    width: 24px;
                                    height: 24px;
                                    border-radius: 50%;
                                    display: flex;
                                    align-items: center;
                                    justify-content: center;
                                    color: #fff;
                                    background: rgba(0, 0, 0, 0.6);
                                    top: 10px;
                                    right: 10px;
                                    cursor: pointer;
                                }
                                .option-title {
                                    display: flex;
                                    align-items: flex-start;
                                    padding: 12px 10px;
                                    .title-icon {
                                        margin-right: 10px;
                                        margin-top: 1px;
                                        .radio-default-icon {
                                            width: 18px;
                                            height: 18px;
                                            border-radius: 50%;
                                            background: #F0F2F7;
                                            border: 1px solid #DCDFE6;
                                        }
                                        .checkbox-default-icon {
                                            width: 18px;
                                            height: 18px;
                                            background: #F0F2F7;
                                            border-radius: 3px;
                                            border: 1px solid #DCDFE6;
                                        }
                                        .iconfont {
                                            font-size: 18px;
                                            color: #20A0FF;
                                        }
                                        &.checkbox {
                                            width: 18px;
                                            height: 18px;
                                            display: flex;
                                            align-items: center;
                                            justify-content: center;
                                            border-radius: 3px;
                                            &.selected {
                                                background: #20A0FF;
                                            }
                                            .iconfont {
                                                color: #fff;
                                                font-size: 14px;
                                            }
                                        }
                                    }
                                    .title-value {
                                        font-size: 14px;
                                        font-family: PingFangSC-Regular, PingFang SC;
                                        font-weight: 400;
                                        color: #333333;
                                        line-height: 20px;
                                    }
                                }
                            }
                        }

                    }
                }
            }
        }
        .operating-view {
            height: 100px;
            background: #FFFFFF;
            display: flex;
            align-items: center;
            justify-content: center;
            .el-button {
                width: 120px;
                margin-right: 24px;
                &.reject {
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #20A0FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #20A0FF;
                    line-height: 14px;
                }
            }
        }
    }
    /deep/ .el-form {
        .el-form-item {
            margin-bottom: 6px;
        }
        .el-form-item__label {
            color: #555;
        }
        .bold {
            .el-form-item__label {
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
            }
        }
        .el-form-item__content {
            line-height: 24px;
            margin-top: 8px;
            color: #999;
        }
        .is-required {
            .el-form-item__label {
                &:before {
                    content: "*";
                    display: inline-block;
                    color: #F56C6C;
                    margin-right: 4px;
                }
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
}
/deep/ .el-table {
    &::before {
        height: 0;
    }
    .el-table__row {
        &:last-of-type {
            td {
                border: none;
            }
        }
    }
    th {
        background: #f2f2f2!important;
        font-size: 14px!important;
        font-family: PingFangSC-Medium, PingFang SC!important;
        font-weight: 500!important;
        color: #333333!important;
        height: 44px!important;
        padding: 0!important;
    }
}

.table-footer {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px 0 42px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    border-top: 1px solid #EBEEF5;
    .count {
        color: #F53341;
    }
    .pagination {
        margin-top: 12px;
    }
}
</style>

